import axios from 'axios'
import {baseUrl} from '../apiconfig'
import {useTokenInfoStore}  from '@/store/tokenInfo'
import {Modal} from 'ant-design-vue'



const axiosInstance = axios.create({
    baseURL: baseUrl,
    timeout: 60000,

});

axiosInstance.interceptors.request.use(
    (config) =>{
        const tokenInfoStore = useTokenInfoStore();
        const token = tokenInfoStore.tokenInfo;
        if(token && config.headers){
            config.headers['Authorization'] = token;
        }
        return config;
    },
    (error) =>{
        Promise.reject(error);
    }
);


axiosInstance.interceptors.response.use(
    (response) => {
        return response.data;
    },
    (err) =>{
        console.log("error",err)
        Modal.error({
            title: err.response.status,
            content: err.message,
        });
    }
)


export default axiosInstance

